package com.zmz.lambda;

/**
 * Create with IntelliT IDEA
 *
 * @Author: zhengmingzhe
 * @Date: 2022/07/30/18:41
 * @Description: lambda 实现接口调用类的构造方法
 */
class Item {
    int id;
    String name;
    double price;

    public Item(int id, String name, double price) {
        this.id = id;
        this.name = name;
        this.price = price;
    }

    public Item() {

    }

}


public class Lambda03 {
    public static void main(String[] args) {
        //使用无参的构造方法来引用  输出对象com.zmz.lambda.Item@404b9385
        ItemCreatorBlankConstruct construct = () -> new Item();
        Item item1 = construct.getItem();
        System.out.println(item1);

        //使用无参的构造方法来引用  输出对象com.zmz.lambda.Item@404b9385
        ItemCreatorBlankConstruct construct2 = Item::new;
        Item item2 = construct2.getItem();
        System.out.println(item2);

        //使用有的构造方法来引用  输出对象com.zmz.lambda.Item@404b9385
        ItemCreatorParamConstruct construct3 = Item::new;
        Item item3 = construct3.getItem(1, "手机", 9999);
        System.out.println(item3);
    }


}

interface ItemCreatorBlankConstruct {
    Item getItem();
}

interface ItemCreatorParamConstruct {
    Item getItem(int id, String name, double price);
}


